package 创建型.建造者;


/**
 * 建造者模式
 * 工厂模式关注的是创建单个产品，而建造者模式则关注创建符合对象
 */
public class Build {
    public static void main(String[] args) {
        Director director = new Director();
        Product create = director.create(new ConcreteBuilder());
        System.out.println(create.toString());

    }
}

/**
 * Director.java
 * 指挥者
 */
class Director {
    //指挥工人按顺序造房
    public Product create(Builder builder) {
        builder.bulidA();
        builder.bulidB();
        builder.bulidC();
        builder.bulidD();
        return builder.getProduct();
    }
}


/**
 * Builder.java
 * 建造者
 */
abstract class Builder {
    //地基
    abstract void bulidA();

    //钢筋工程
    abstract void bulidB();

    //铺电线
    abstract void bulidC();

    //粉刷
    abstract void bulidD();

    //完工-获取产品
    abstract Product getProduct();
}

/**
 * ConcreteBuilder.java
 * 具体建造者(工人)
 */
class ConcreteBuilder extends Builder {
    private Product product;

    public ConcreteBuilder() {
        product = new Product();
    }

    @Override
    void bulidA() {
        product.setBuildA("地基");
    }

    @Override
    void bulidB() {
        product.setBuildB("钢筋工程");
    }

    @Override
    void bulidC() {
        product.setBuildC("铺电线");
    }

    @Override
    void bulidD() {
        product.setBuildD("粉刷");
    }

    @Override
    Product getProduct() {
        return product;
    }
}

/**
 * Product.java
 * 产品（房子）
 */
class Product {
    private String buildA;
    private String buildB;
    private String buildC;
    private String buildD;

    public String getBuildA() {
        return buildA;
    }

    public void setBuildA(String buildA) {
        this.buildA = buildA;
    }

    public String getBuildB() {
        return buildB;
    }

    public void setBuildB(String buildB) {
        this.buildB = buildB;
    }

    public String getBuildC() {
        return buildC;
    }

    public void setBuildC(String buildC) {
        this.buildC = buildC;
    }

    public String getBuildD() {
        return buildD;
    }

    public void setBuildD(String buildD) {
        this.buildD = buildD;
    }

    @Override
    public String toString() {
        return buildA + "\n" + buildB + "\n" + buildC + "\n" + buildD + "\n" + "房子验收完成";
    }
}
